﻿using System;
using System.Runtime.InteropServices;
using System.Security;

namespace MS.Win32
{
    internal static class UnsafeNativeMethods
    {
        /// <SecurityNote>
        ///     Critical: Registering for system broadcast messages
        /// </SecurityNote>
        [DllImport(ExternDll.User32, SetLastError = true)]
        [SecurityCritical, SuppressUnmanagedCodeSecurity]
        public static extern IntPtr RegisterPowerSettingNotification(IntPtr hRecipient, ref Guid PowerSettingGuid, uint Flags);

        /// <SecurityNote>
        ///     Critical: Unregistering for system broadcast messages
        /// </SecurityNote>
        [DllImport(ExternDll.User32, SetLastError = true)]
        [SecurityCritical, SuppressUnmanagedCodeSecurity]
        public static extern bool UnregisterPowerSettingNotification(IntPtr Handle);

        /// <SecurityNote>
        ///     Critical: Registering for system broadcast messages
        /// </SecurityNote>
        [SecurityCritical, SuppressUnmanagedCodeSecurity]
        [DllImport(ExternDll.User32, SetLastError = true)]
        public static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, IntPtr NotificationFilter, uint Flags);

        /// <SecurityNote>
        ///     Critical: Unregistering for system broadcast messages
        /// </SecurityNote>
        [SecurityCritical, SuppressUnmanagedCodeSecurity]
        [DllImport(ExternDll.User32, SetLastError = true)]
        public static extern bool UnregisterDeviceNotification(IntPtr Handle);

        [DllImport(ExternDll.Powrprof, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SetSuspendState([MarshalAs(UnmanagedType.I1)]bool Hibernate, [MarshalAs(UnmanagedType.I1)]bool ForceCritical, [MarshalAs(UnmanagedType.I1)]bool DisableWakeEvent);
    }
}
